package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysRoleMenuService;
import com.atguigu.spzx.model.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Tag(name = "角色菜单管理模块")
@RequestMapping("/admin/system/roleMenu")
public class SysRoleMenuController {
    @Resource
    SysRoleMenuService sysRoleMenuService;
    @Operation(summary = "给角色分配菜单")
    @PutMapping("assignMenus2Role/{roleId}")
    public Result assignMenus2Role(@PathVariable("roleId")Long roleId,
                                   @RequestBody List<Long> menuIds){
        sysRoleMenuService.assignMenus2Role(roleId,menuIds);
        return Result.ok();
    }

    @Operation(summary = "查询所有可用菜单和已分配菜单id集合接口")
    @GetMapping("findMenusByRoleId/{roleId}")
    public Result findMenusByRoleId(@PathVariable("roleId") Long roleId){
        Map<String , Object> map = sysRoleMenuService.findMenusByRoleId(roleId);
        return Result.ok().data(map);
    }
}
